package com.wowangz.cms.jpush.service;

import java.rmi.server.ServerCloneException;
import java.util.List;
import java.util.Map;

import com.wowangz.cms.common.utils.SysConstant;
import com.wowangz.cms.component.datagrid.pojo.DataResult;
import com.wowangz.cms.component.datagrid.pojo.DataStyle;
import com.wowangz.cms.component.datagrid.pojo.PangingParam;
import com.wowangz.cms.component.datagrid.utils.DataTypeConstant;
import com.wowangz.cms.component.datagrid.utils.PangingTools;
import com.wowangz.cms.jpush.pojo.Jpush;
import com.wowangz.cms.syscore.service.BaseService;

public class JpushService extends BaseService {

	public Jpush getJpushInfo(Map<String, Object> paramsMap) {
		return getSqlSession().selectOne("jPushService.getJpushInfo", paramsMap);
	}
	
	public List<Jpush> getJpushInfoList(Map<String, Object> paramsMap) {
		return getSqlSession().selectList("jPushService.getJpushInfoList", paramsMap);
	}
	
	public Integer getJpushInfoCount(Map<String, Object> paramsMap) {
		return getSqlSession().selectList("jPushService.getJpushInfoCount", paramsMap).size();
	}
	
	/**
	 * 获得一个 DataResult对象
	 * 
	 * @param pangingParam
	 * @param map
	 * @return
	 * @throws ServerCloneException
	 */
	public DataResult getDataResult(PangingParam pangingParam, Map<String, Object> paramsMap) throws ServerCloneException {
		paramsMap.put("statusid", SysConstant.YesOrNo.YES);
		long resultCount = getJpushInfoCount(paramsMap);
		List<Jpush> jpushInfoList = getJpushInfoList(paramsMap);
		DataStyle dataStyle = new DataStyle();
		dataStyle.setPageIndex(pangingParam.getPage());
		dataStyle.setDataCount(resultCount);
		dataStyle.setDataList(jpushInfoList);
		dataStyle.addDepict("storeid", DataTypeConstant.LONG);
		dataStyle.addDepict("username", DataTypeConstant.STRING);
		dataStyle.addDepict("title", DataTypeConstant.STRING);
		dataStyle.addDepictByFunction("allperson", SysConstant.BoradAllperson.class, "getName", new Class[] { long.class });
		dataStyle.addDepict("savetime", DataTypeConstant.LONG);
		dataStyle.addDepict("pushname", DataTypeConstant.STRING);
		dataStyle.addDepict("storename", DataTypeConstant.STRING);
		dataStyle.addDepict("inputtime", DataTypeConstant.DATE);
		dataStyle.addDepictByFunction("statusid", SysConstant.RecordStatus.class, "getName", new Class[] { long.class });
		dataStyle.addDepict("id", DataTypeConstant.LONG);
		DataResult dataResult = PangingTools.buildResultPagerInfo(dataStyle);
		return dataResult;
	}

}
